<?
include("../functions/functions.php");

if (isset($_POST['Year'])) {
	$thisYear = $_POST['Year']	;
}
else {
	$thisYear = date("Y");
}

$lastYear = $thisYear-1;
$reportTitle = "First time visitors for the financial year of $lastYear/$thisYear shown in the month of there first visit.";

$totalStaff = 0;
$year = 0;
$site = 0;
$month = 0;
$year = 0;
$totalUniqueClients = 0;
$totalMonthly1 = 0;
$totalMonthly2 = 0;
$totalMonthly3 = 0;
$total1 = 0;
$total2 = 0;
$total3 = 0;
$site1 = "";
$site2 = "";
$site3 = "";
$lastMonth = "";
$monthlyTotal = 0;
$i = 0;
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title><? echo $reportTitle; ?></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="reports.css" rel="stylesheet" type="text/css">
</head>

<body bgcolor="#FFFFFF" text="#000000" link="#0075C5" vlink="#0075C5" alink="#C5DDF4" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<?
echo "<p style=\"text-align:center; font-size: 16pt\">$reportTitle</h3>";
?>
<table width="100%" border="0">
	<tr>
		<td width="50%">
			<form method="post">
				Select the financial year to report on: <select name="Year" onChange="submit();">
					<?
					$years = getBeginEndYears();
					for ($j = $years[start]; $j<$years[end]; $j++) {
						$option = ($j-1)." - ".$j;
						if ($thisYear == $j)
							$select = "SELECTED";
						else
							$select = "";
						echo "<option value=\"$j\" $select>$option</option>";
					}
					?>
				</select>
			</form>
		</td>
		<td align="right" width="50%"><? echo getCurrentDate(); ?></td>
	</tr>
</table>
<?

echo "<p>Each person counted once in a financial year in the first month they presented for ER</p>";

echo "<table width=\"100%\" cellpadding=\"3\" cellspacing=\"0\" border=\"1\" bordercolor=\"#000000\" class=\"body\" FRAME=BOX RULES=GROUPS>";

echo "<tbody><tr>
				<td class=\"bodybold\" style=\"width:50%;\">Site Name</td>
				<td class=\"bodybold\" style=\"width:50%;\">Site Total</td>
			</tr></tbody>";

$current_year = 2007;
$selected_month = 08;

$sql = "SELECT * from er_client WHERE first_visit >= '$current_year-$selected_month-01 AND first_visit =< $current_year-$selected_month-32'";

//echo $sql;

$results = r_db($sql);

	echo "<table width = \"99%\" border=\"1\" align=\"center\">";
	echo "<tr>\n";
	echo "<td>TEST</td>";



while($row = mysql_fetch_array($results))
{

  	$first_visit = $row["first_visit"];


	echo "</tr><tr>";
	echo "<td >$first_visit</td>";

	echo "</tr>";
}
?>
</body>
</html>
